package com.ruoyi.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.domain.AdvTemple;
import com.ruoyi.service.AdvTempleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

@RestController
@RequestMapping("/system/temple")
public class AdvTempleController extends BaseController {

    @Autowired
    private AdvTempleService advTempleService;

    /**
     * 查询列表
     */
    @PreAuthorize("@ss.hasPermi('system:advTemple:list')")
    @GetMapping("/list")
    public TableDataInfo list(AdvTemple advTemple)
    {
        startPage();
        List<AdvTemple> list = advTempleService.selectAdvTempleList(advTemple);
        return getDataTable(list);
    }

    /**
     * 导出列表
     */
    @PreAuthorize("@ss.hasPermi('system:advTemple:export')")
    @Log(title = "", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AdvTemple advTemple)
    {
        List<AdvTemple> list = advTempleService.selectAdvTempleList(advTemple);
        ExcelUtil<AdvTemple> util = new ExcelUtil<AdvTemple>(AdvTemple.class);
        util.exportExcel(response, list, "数据");
    }

    /**
     * 新增
     */
    @RepeatSubmit
    @PreAuthorize("@ss.hasPermi('system:advTemple:add')")
    @Log(title = "", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AdvTemple advTemple)
    {
        return toAjax(advTempleService.insertAdvTemple(advTemple));
    }

    /**
     * 修改
     */
    @PreAuthorize("@ss.hasPermi('system:advTemple:edit')")
    @Log(title = "", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AdvTemple advTemple)
    {
        return toAjax(advTempleService.updateAdvTemple(advTemple));
    }

    /**
     * 删除
     */
    @PreAuthorize("@ss.hasPermi('system:advTemple:remove')")
    @Log(title = "", businessType = BusinessType.DELETE)
    @DeleteMapping("/{advTempleIds}")
    public AjaxResult remove(@PathVariable Long[] advTempleIds)
    {
        return toAjax(advTempleService.deleteAdvTempleByAdvTempleId(advTempleIds));
    }


}
